package com.pojoin.cms.domain.persistence;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.pojoin.cms.domain.Resource;
import com.pojoin.cms.domain.User;
import com.pojoin.cms.domain.alter.RoleAlter;

@Entity
@Table(name = "role")
public class RolePersistence extends RoleAlter {

	@Override
	@Column
	public Date getCreateDate() {
		return super.getCreateDate();
	}

	@Override
	@Column
	public Integer getDeleted() {
		return super.getDeleted();
	}

	@Override
	@Column
	public String getRemark() {
		return super.getRemark();
	}

	@Override
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getRoleId() {
		return super.getRoleId();
	}

	@Override
	@Column
	public String getRoleName() {
		return super.getRoleName();
	}

	@Override
	@Column
	public String getRoleTitle() {
		return super.getRoleTitle();
	}

	@Override
	@ManyToMany(mappedBy = "roles", targetEntity = UserPersistence.class, fetch = FetchType.EAGER)
	public Set<User> getUsers() {
		return super.getUsers();
	}
	
	@Override
	@ManyToMany(
			targetEntity=ResourcePersistence.class,
			fetch=FetchType.EAGER
			)
	@JoinTable(
			name="role_resource",
			joinColumns={@JoinColumn(name="roleId")},
			inverseJoinColumns={@JoinColumn(name="resourceId")}
			)
	public Set<Resource> getResources() {
		return super.getResources();
	}
	
	public void setRoleId(Long id){
		this.roleId = id;
	}

}
